package ${basePackage}.service.${className?lower_case};

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;

import ${basePackage}.dto.Pagination;
import ${basePackage}.entity.${className};
import ${basePackage}.repository.${className}Dao;

/**
 * ${className} 管理类.
 * 
 * @author creator
 */

@Component
@Transactional(readOnly = true)
public class ${className}Service
{

	private static Logger logger = LoggerFactory.getLogger(${className}Service.class);

	private ${className}Dao ${className?lower_case}Dao;

	/**
	 * 分页查询
	 * 
	 * @return Page<${className}>
	 */
	public Page<${className}> get${className}sByPage(Map<String, Object> filterParams, Pagination pagination)
	{

		PageRequest pageRequest = new PageRequest(pagination.getPageNum(), pagination.getNumPerPage(), Direction.ASC, pagination.getOrderField());

		Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
		//filters.put("dlt", new SearchFilter("dlt", Operator.EQ, 0));
		Specification<${className}> spec = DynamicSpecifications.bySearchFilter(filters.values(), ${className}.class);

		return ${className?lower_case}Dao.findAll(spec, pageRequest);
	}

	public ${className} get${className}(Integer id)
	{

		return ${className?lower_case}Dao.findOne(id);
	}

	@Transactional(readOnly = false)
	public void save${className}(${className} entity)
	{

		${className?lower_case}Dao.save(entity);
	}

	@Transactional(readOnly = false)
	public void delete${className}(Integer id)
	{

		${className?lower_case}Dao.delete(id);
	}

	@Autowired
	public void set${className}Dao(${className}Dao ${className?lower_case}Dao)
	{

		this.${className?lower_case}Dao = ${className?lower_case}Dao;
	}

}

  